<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=0.5,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no, email=no" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <!-- 删除苹果默认的工具栏和菜单栏 -->
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <!-- 设置苹果工具栏颜色 -->
    <meta name="format-detection" content="telphone=no, email=no" />
    <!-- 忽略页面中的数字识别为电话，忽略email识别 -->
    <!-- 启用360浏览器的极速模式(webkit) -->
    <meta name="renderer" content="webkit">
    <!-- 避免IE使用兼容模式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 针对手持设备优化，主要是针对一些老的不识别viewport的浏览器，比如黑莓 -->
    <meta name="HandheldFriendly" content="true">
    <!-- 微软的老式浏览器 -->
    <meta name="MobileOptimized" content="320">
    <!-- uc强制竖屏 -->
    <meta name="screen-orientation" content="portrait">
    <!-- QQ强制竖屏 -->
    <meta name="x5-orientation" content="portrait">
    <!-- UC强制全屏 -->
    <meta name="full-screen" content="yes">
    <!-- QQ强制全屏 -->
    <meta name="x5-fullscreen" content="true">
    <!-- UC应用模式 -->
    <meta name="browsermode" content="application">
    <!-- QQ应用模式 -->
    <meta name="x5-page-mode" content="app">
    <!-- windows phone 点击无高光 -->
    <meta name="msapplication-tap-highlight" content="no">
    <title>虾客云-客户管理</title>
    <link rel="stylesheet" href="{{asset('css/reset.css')}}">
    <link rel="stylesheet" href="{{asset('css/main.css')}}">
    <link rel="stylesheet" href="{{asset('css/index.css')}}">
    <link rel="stylesheet" href="{{asset('css/yd_rl.css')}}" />
    <link rel="stylesheet" href="{{asset('css/LCalendar.css')}}" />
</head>
<body>
    <!-- 公共头部 -->
    <div class="g2_head-bg">
        <!-- 返回上一层 -->
        <p class="g2_head_goback-bg fl">
            <a href="javascript:history.back(-1)">
                <img src="{{asset('images/xky_icon0-1.png')}}" class="g2_head_goback_icon fl" alt="">
                <span class="g2_head_goback_del fl">返回</span>
            </a>
        </p>
        <p class="ym-tit fl">客户列表</p>
        <span class="g2_head_goback_del fr khtj_sx khlb_sx" style="display:block;">筛选</span>
        <div class="cl"></div>
    </div>
    <div class="g2_head-bg2"></div> 
    <!-- 客户管理  客户列表 -->
    <div class="cjd_skjl-bg" id="khlb1">
        <div id="kaikuo">
            @foreach($customer as $vo)
            <div class="cjd_khgllb-bg kehulist"  myAttr="true">
                <input type="hidden" name="listid" value="{{$vo->id}}">
                <p class="cjd_khgllb_khname fl">{{$vo->customer_name}}</p>
                <p class="cjd_khgllb_iphone fl">{{$vo->customer_phone}}</p>
                <span class="cjd_khgllb_srtx fr">生日提醒</span>
                <p class="cjd_ykxq_sfzh fl">{{$vo->customer_danwei}}</p>
                <span class="cjd_ykxq_sp fr">{{$vo->tixing}}</span>
                <div class="cl"></div>
            </div>
            @endforeach
        </div>
        <!-- 加载更多按钮 -->
        <div class="jzmore-bg" style="margin-bottom:22vw;" id="jiazai">
            <img src="{{asset('images/jiazai.png')}}" alt="">
            <span>加载更多</span>
        </div>
        <a href="{{url('xiadan')}}">
            <input type="button" class="gdlb_xd-btn" value="下单">
        </a>
        <input type="hidden" id="customer_ids" name="customer_id" value="">
        <form action="" id="customer_form">
            <input type="hidden" id="listid" name="listid" value="">
            <input type="hidden" id="moban" name="moban" value="">
        </form>
        <div class="khgl_khlbbtn-bg">
            <input type="button" class="khgl_khlbbtn khlbfsdx_btn fl" value="发送短信" readonly>
            <input type="button" class="khgl_khlbbtn khlbxzkh_btn fl" style="margin-left:0.2%;" value="新增客户" readonly>
            <input type="button" class="khgl_khlbbtn khlbbjzl_btn fr" value="编辑资料" readonly>
            <div class="cl"></div>
        </div>
    </div>

    <!-- 客户列表 短信列表 -->
    <div class="khlb_dxlb-bg" id="khlb2">
        <ul class="khlb_dxlb-bg2">
            @foreach($duanxin as $vo)
            <li class="khlb_dxlb duanxinlist">
                <input type="hidden" name="duanxinid" value="{{$vo->id}}">
                <p class="khlb_dxlb-tit">{{$vo->title}}</p>
                <span class="khlb_dxlb_del">
                    {{$vo->content}}
                </span>
            </li>
            @endforeach
            <input type="button" id="fasong" class="khlb_dxlb_fsbtn" style="width:100%;" value="发送短信" readonly>
        </ul>
    </div>
    <!-- 客户列表 筛选条件 -->
    <div class="khlb_sx-bg" id="khlb3">
        <form action="" id="kehusousuo">
            <input type="hidden" id="shuliang" name="shuliang" value="{{$shuliang}}">
            <ul class="khs2">
                <li class="khs2_list">
                    <p class="khs2_tit fl">客户类别</p>
                    <span class="sewv fl">
                        <span class="sewvtop">
                            <input type="text" name="customer_type" class="khs2_del fl" placeholder="请选择客户类别" value="">
                            <em>
                                <img src="{{asset('images/xky_icon9.png')}}">
                            </em>
                        </span>
                        <ul class="sewvbm">
                            <li>单位</li>
                            <li>个人</li>
                        </ul>
                    </span>
                    <div class="cl"></div>
                </li>
                <li class="khs2_list">
                    <p class="khs2_tit fl">客户来源</p>
                    <span class="sewv fl">
                        <span class="sewvtop">
                            <input type="text" name="customer_laiyuan" class="khs2_del fl" placeholder="请选择客户来源" value="">
                            <em>
                                <img src="{{asset('images/xky_icon9.png')}}">
                            </em>
                        </span>
                        <ul class="sewvbm">
                            <li>网站</li>
                            <li>转介绍</li>
                            <li>上门</li>
                            <li>电话销售</li>
                            <li>电话销售</li>
                            <li>老客户</li>
                            <li>其他</li>
                        </ul>
                    </span>
                    <div class="cl"></div>
                </li>
                <li class="khs2_list">
                    <p class="khs2_tit fl">客户姓名</p>
                    <input type="text" name="customer_name" class="khs2_del fl" placeholder="请填写客户姓名" value="">
                    <div class="cl"></div>
                </li>
                <li class="khs2_list">
                    <p class="khs2_tit fl">客户电话</p>
                    <input type="text" name="customer_phone" class="khs2_del fl" placeholder="请填写客户电话" value="">
                    <div class="cl"></div>
                </li>
                <li class="khs2_list">
                    <p class="khs2_tit fl">单位名称</p>
                    <input type="text" name="customer_danwei" class="khs2_del fl" placeholder="请填写客户单位名称" value="">
                    <div class="cl"></div>
                </li>
                <li class="khs2_list">
                    <p class="khs2_tit fl">维护人</p>
                    <input type="text" name="yuangong" class="khs2_del fl" placeholder="请填写客户单位名称" value="">
                    <div class="cl"></div>
                </li>
                <input type="button" id="sousuo" class="gdsx_search-btn" value="搜索">
            </ul>
        </form>
    </div>
    <!-- 客户列表 编辑资料 -->
    <div class="khlb_bjzl-bg" id="khlb4">
        <form action="" id="customerbianji">
            <input type="hidden" name="id" value="">
            <ul class="grzx_xq-bg">
                <li class="grzx_xq_list">
                    <p class="grzx_xgname fl" style="color:red;">客户来源*</p>
                    <span class="sewv fr">
                        <span class="sewvtop">
                            <input type="text" name="customer_laiyuan" style="height:12vw;border:none;font-size:1.6rem;width:88%;" value="" placeholder="请选择客户来源">
                            <em>
                                <img src="{{asset('images/xky_icon9.png')}}">
                            </em>
                        </span>
                        <ul class="sewvbm">
                            <li>网站</li>
                            <li>转介绍</li>
                            <li>上门</li>
                            <li>电话销售</li>
                            <li>老客户</li>
                            <li>其他</li>
                        </ul>
                    </span>
                    <div class="cl"></div>
                </li>
                <li class="grzx_xq_list">
                    <p class="grzx_xgname fl" style="color:red;">客户姓名*</p>
                    <p class="grzx_xgname_del grzx_xgsjhm-bg fr">
                        <input type="text" name="customer_name" placeholder="请输入客户姓名" class="grzx_xgsjhm" value="">
                    </p>
                    <div class="cl"></div>
                </li>
                <li class="grzx_xq_list">
                    <p class="grzx_xgname fl">客户年龄</p>
                    <p class="grzx_xgname_del grzx_xgsjhm-bg fr">
                        <input type="text" name="customer_age" placeholder="请输入客户年龄" class="grzx_xgsjhm" value="">
                    </p>
                    <div class="cl"></div>
                </li>
                 <li class="grzx_xq_list">
                    <p class="grzx_xgname fl">性别</p>
                    <p class="grzx_xgname_del fr">
                        <label class="grzx_sexinp-bg fr">
                            <input class="grzx_sexinp fr" name="customer_sex" id="nv" type="radio" value="2" />
                            <span class="fr" style="margin-right:5%;">女</span>
                        </label>
                        <label class="grzx_sexinp-bg fr">
                            <input class="grzx_sexinp fr" name="customer_sex"  id="nan" type="radio" value="1" />
                            <span class="fr" style="margin-right:5%;">男</span>
                        </label>
                    </p>
                    <div class="cl"></div>
                </li>
                <li class="grzx_xq_list">
                    <p class="grzx_xgname fl">客户电话</p>
                    <p class="grzx_xgname_del grzx_xgsjhm-bg fr">
                        <input type="text" id="phone" name="customer_phone" placeholder="请输入客户联系电话" class="grzx_xgsjhm" value="">
                    </p>
                    <div class="cl"></div>
                </li>
                <li class="grzx_xq_list">
                    <p class="grzx_xgname fl">客户微信</p>
                    <p class="grzx_xgname_del grzx_xgsjhm-bg fr">
                         <input type="text" name="customer_weixin" placeholder="请输入客户微信" class="grzx_xgsjhm" value="">
                    </p>
                    <div class="cl"></div>
                </li>
                <li class="grzx_xq_list">
                    <p class="grzx_xgname fl">客户QQ</p>
                    <p class="grzx_xgname_del grzx_xgsjhm-bg fr">
                        <input type="text" name="customer_qq" placeholder="请输入客户QQ" class="grzx_xgsjhm" value="">
                    </p>
                    <div class="cl"></div>
                </li>
                <li class="grzx_xq_list">
                    <p class="grzx_xgname fl">客户邮箱</p>
                    <p class="grzx_xgname_del grzx_xgsjhm-bg fr">
                        <input type="text" name="customer_email" placeholder="请输入电子邮箱" class="grzx_xgsjhm" value="">
                    </p>
                    <div class="cl"></div>
                </li>
                <li class="grzx_xq_list">
                    <p class="grzx_xgname fl">身份证号</p>
                    <p class="grzx_xgname_del grzx_xgsjhm-bg fr">
                        <input type="text" name="customer_sfz" placeholder="请输入身份证号" class="grzx_xgsjhm" value="">
                    </p>
                    <div class="cl"></div>
                </li>
                <li class="grzx_xq_list">
                    <p class="grzx_xgname fl" style="color:red;">客户类别*</p>
                    <span class="sewv fr" style="text-align:right;">
                        <span class="sewvtop">
                            <input type="text" name="customer_type" style="height:12vw;border:none;font-size:1.6rem;width:88%;" value="" placeholder="请选择客户类别">
                            <em>
                                <img src="images/xky_icon9.png">
                            </em>
                        </span>
                        <ul class="sewvbm">
                            <li>单位</li>
                            <li>个人</li>
                        </ul>
                    </span>
                    <div class="cl"></div>
                </li>
                <li class="grzx_xq_list">
                    <p class="grzx_xgname fl" style="color:red;">单位名称*</p>
                    <p class="grzx_xgname_del grzx_xgsjhm-bg fr">
                        <input type="text" name="customer_danwei" placeholder="请输入单位名称" class="grzx_xgsjhm" value="">
                    </p>
                    <div class="cl"></div>
                </li>
                <li class="grzx_xq_list">
                    <p class="grzx_xgname fl">备注</p>
                    <p class="grzx_xgname_del grzx_xgsjhm-bg fr">
                        <input type="text" name="customer_beizhu" placeholder="请输入工单备注" class="grzx_xgsjhm" value="">
                    </p>
                    <div class="cl"></div>
                </li>
            </ul>
            <div style="width:100%;height:20vw;"></div>
            <input type="button" id="bianjibaoxun" class="khlb_bjzl-btn" value="保 存">
        </form>
    </div>
    <!-- 客户列表 新增 -->
    <div class="khlb_bjzl-bg" id="khlb5">
        <form action="" id="tianjiaform">
            <ul class="grzx_xq-bg">
                <li class="grzx_xq_list">
                    <p class="grzx_xgname fl" style="color:red;">客户来源*</p>
                    <span class="sewv fr">
                        <span class="sewvtop">
                            <input type="text" name="customer_laiyuan" style="height:12vw;border:none;font-size:1.6rem;width:88%;" value="" placeholder="请选择客户来源">
                            <em>
                                <img src="{{asset('images/xky_icon9.png')}}">
                            </em>
                        </span>
                        <ul class="sewvbm">
                            <li>网站</li>
                            <li>转介绍</li>
                            <li>上门</li>
                            <li>电话销售</li>
                            <li>老客户</li>
                            <li>其他</li>
                        </ul>
                    </span>
                    <div class="cl"></div>
                </li>
                <li class="grzx_xq_list">
                    <p class="grzx_xgname fl" style="color:red;">客户姓名*</p>
                    <p class="grzx_xgname_del grzx_xgsjhm-bg fr">
                        <input type="text" name="customer_name" placeholder="请输入客户姓名" class="grzx_xgsjhm" value="">
                    </p>
                    <div class="cl"></div>
                </li>
                <li class="grzx_xq_list">
                    <p class="grzx_xgname fl">客户年龄</p>
                    <p class="grzx_xgname_del grzx_xgsjhm-bg fr">
                        <input type="text" name="customer_age" placeholder="请输入客户年龄" class="grzx_xgsjhm" value="">
                    </p>
                    <div class="cl"></div>
                </li>
                 <li class="grzx_xq_list">
                    <p class="grzx_xgname fl">性别</p>
                    <p class="grzx_xgname_del fr">
                        <label class="grzx_sexinp-bg fr">
                            <input class="grzx_sexinp fr" name="customer_sex" type="radio" value="2" />
                            <span class="fr" style="margin-right:5%;">女</span>
                        </label>
                        <label class="grzx_sexinp-bg fr">
                            <input class="grzx_sexinp fr" name="customer_sex" type="radio" checked="checked" value="1" />
                            <span class="fr" style="margin-right:5%;">男</span>
                        </label>
                    </p>
                    <div class="cl"></div>
                </li>
                <li class="grzx_xq_list">
                    <p class="grzx_xgname fl">客户电话</p>
                    <p class="grzx_xgname_del grzx_xgsjhm-bg fr">
                        <input type="text" id="phone" name="customer_phone" placeholder="请输入客户联系电话" class="grzx_xgsjhm" value="">
                    </p>
                    <div class="cl"></div>
                </li>
                <li class="grzx_xq_list">
                    <p class="grzx_xgname fl">客户微信</p>
                    <p class="grzx_xgname_del grzx_xgsjhm-bg fr">
                         <input type="text" name="customer_weixin" placeholder="请输入客户微信" class="grzx_xgsjhm" value="">
                    </p>
                    <div class="cl"></div>
                </li>
                <li class="grzx_xq_list">
                    <p class="grzx_xgname fl">客户QQ</p>
                    <p class="grzx_xgname_del grzx_xgsjhm-bg fr">
                        <input type="text" name="customer_qq" placeholder="请输入客户QQ" class="grzx_xgsjhm" value="">
                    </p>
                    <div class="cl"></div>
                </li>
                <li class="grzx_xq_list">
                    <p class="grzx_xgname fl">客户邮箱</p>
                    <p class="grzx_xgname_del grzx_xgsjhm-bg fr">
                        <input type="text" name="customer_email" placeholder="请输入电子邮箱" class="grzx_xgsjhm" value="">
                    </p>
                    <div class="cl"></div>
                </li>
                <li class="grzx_xq_list">
                    <p class="grzx_xgname fl">身份证号</p>
                    <p class="grzx_xgname_del grzx_xgsjhm-bg fr">
                        <input type="text" name="customer_sfz" placeholder="请输入身份证号" class="grzx_xgsjhm" value="">
                    </p>
                    <div class="cl"></div>
                </li>
                <li class="grzx_xq_list">
                    <p class="grzx_xgname fl" style="color:red;">客户类别*</p>
                    <span class="sewv fr" style="text-align:right;">
                        <span class="sewvtop">
                            <input type="text" name="customer_type" style="height:12vw;border:none;font-size:1.6rem;width:88%;" value="" placeholder="请选择客户类别">
                            <em>
                                <img src="images/xky_icon9.png">
                            </em>
                        </span>
                        <ul class="sewvbm">
                            <li>单位</li>
                            <li>个人</li>
                        </ul>
                    </span>
                    <div class="cl"></div>
                </li>
                <li class="grzx_xq_list">
                    <p class="grzx_xgname fl" style="color:red;">单位名称*</p>
                    <p class="grzx_xgname_del grzx_xgsjhm-bg fr">
                        <input type="text" name="customer_danwei" placeholder="请输入单位名称" class="grzx_xgsjhm" value="">
                    </p>
                    <div class="cl"></div>
                </li>
                <li class="grzx_xq_list">
                    <p class="grzx_xgname fl">备注</p>
                    <p class="grzx_xgname_del grzx_xgsjhm-bg fr">
                        <input type="text" name="customer_beizhu" placeholder="请输入工单备注" class="grzx_xgsjhm" value="">
                    </p>
                    <div class="cl"></div>
                </li>
            </ul>
            <div style="width:100%;height:20vw;"></div>
            <input type="button" id="tianjia" class="khlb_bjzl-btn" value="保 存">
        </form>
    </div> 
    <!-- 遮罩 -->
    <!-- loading 小圆圈 -->
    <div class="z2_loading-bg" style="width:100%;height:100%;background:rgba(255,255,255,0.6);position:fixed;;left:0;top:0;">
        <img src="{{asset('images/loading1.gif')}}" style="width:10%;position:fixed;left:0;right:0;top:0;bottom:0;margin:auto;" alt="">
    </div>
    <!-- loadning对号 -->
    <div class="duihao" style="width:100%;height:100%;position:fixed;;left:0;top:0;display:none;">
        <img src="{{asset('images/duihao.png')}}" style="width:10%;position:fixed;left:0;right:0;top:0;bottom:0;margin:auto;" alt="">
    </div>
     <!-- 提示信息 --> 
    <p id="tishi" style="display:none;position:fixed;left:0;right:0;top:0;bottom:0;margin:auto;width:94%;height:8vw;line-height:8vw;color:#fff;font-size:1.6rem;text-align:center;background:rgba(0,0,0,0.5);border-radius:4px;"></p>
    <script src="{{asset('js/jquery.min.js')}}"></script>
    <script src="{{asset('js/fastclick.min.js')}}"></script>
</body>
    <script src="{{asset('js/LCalendar.js')}}" type="text/javascript" charset="utf-8"></script>
    <script src="{{asset('js/index.js')}}" type="text/javascript" charset="utf-8"></script>
    <script>
    $(function () {
        FastClick.attach(document.body);
    });
    window.onload = function (event) {
        location.hash = 'khlb1';
        $("#khlb1").show();
        $("#khlb2").hide();
        $("#khlb3").hide();
        $("#khlb4").hide();
        $("#khlb5").hide();
        $(".z2_loading-bg").hide();
    }
    // 点击加载按钮
    $("#jiazai").click(function(){
        var shu=$("#shuliang").val();
        $("#shuliang").val(shu*1+10);
        var d = {};
        var t = $('#kehusousuo').serializeArray();
        $.each(t, function() {
          d[this.name] = this.value;
        });
        var data=JSON.stringify(d);
        // alert(data);
        $.ajax({
            url:"{{url('kehusousuo')}}",
            type:'post', //GET
            async:false,    //或false,是否异步
            data:{'_token':'{{csrf_token()}}','data':data},
            dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
            beforeSend:function(){
                console.log('发送前');
                $('.z2_loading-bg').show();
            },
            success:function(data){
                if(data=="false"){
                    $('.z2_loading-bg').hide();
                    $("#tishi").html('搜索失败');
                    $("#tishi").stop(true, true).fadeIn('fast');
                    $("#tishi").fadeOut(1500);
                    window.location.href = "{{url('/')}}";
                }else{
                    var html="";
                    $.each(data.order,function(i,item){
                        html+="<div class=\"cjd_khgllb-bg kehulist\"  myAttr=\"true\"><input type=\"hidden\" name=\"listid\" value=\""+item.id+"\"><p class=\"cjd_khgllb_khname fl\">"+item.customer_name+"<\/p><p class=\"cjd_khgllb_iphone fl\">"+item.customer_phone+"<\/p><span class=\"cjd_khgllb_srtx fr\">生日提醒<\/span><p class=\"cjd_ykxq_sfzh fl\">"+item.customer_danwei+"<\/p><span class=\"cjd_ykxq_sp fr\">"+item.tixing+"<\/span><div class=\"cl\"><\/div><\/div>";
                　　});
                    $("#kaikuo").html(html);
                    $("#shuliang").val(data.shuliang);
                    // 选择客户之后 发送短信
                    $('.cjd_khgllb-bg').click(function(){
                        if($(this).attr("myAttr")=="true"){
                            $("#customer_ids").val($("#customer_ids").val()+$(this).children().eq(0).val()+',');
                            $(this).attr("myAttr","false");
                            $(this).css('background', '#eaeaea');
                        }else{
                            $("#customer_ids").val($("#customer_ids").val().replace($(this).children().eq(0).val()+',', ""));
                            $(this).attr("myAttr","true");
                            $(this).css('background', '#fff');
                        }
                    })
                }
            }, 
            complete:function(){
                location.hash = 'khlb1';
                $("#khlb1").show();
                $("#khlb2").hide();
                $("#khlb3").hide();
                $("#khlb4").hide();
                $("#khlb5").hide();
                $('.z2_loading-bg').hide();
                $('.duihao').show();
                $('.duihao').hide(1000);
            }
        })
    })
    // 执行客户新增
    $(function () {
        $("#tianjia").click(function(){
            if($("#tianjiaform input[name='customer_laiyuan']").val()==''){
                $("#tishi").html('客户来源必须选择');
                $("#tishi").stop(true, true).fadeIn('fast');
                $("#tishi").fadeOut(1500);
            }else if($("#tianjiaform input[name='customer_name']").val()==''){
                $("#tishi").html('客户姓名必须输入');
                $("#tishi").stop(true, true).fadeIn('fast');
                $("#tishi").fadeOut(1500);
            }else if($("#tianjiaform input[name='customer_phone']").val() !='' && $("#tianjiaform input[name='customer_phone']").val().length !=11){
                $("#tishi").html('客户电话必须为11位');
                $("#tishi").stop(true, true).fadeIn('fast');
                $("#tishi").fadeOut(1500);
            }else if($("#tianjiaform input[name='customer_sfz']").val() !='' && $("#tianjiaform input[name='customer_sfz']").val().length !=18){
                $("#tishi").html('身份证号码必须18位');
                $("#tishi").stop(true, true).fadeIn('fast');
                $("#tishi").fadeOut(1500);
            }else if($("#tianjiaform input[name='customer_type']").val()==''){
                $("#tishi").html('客户类别');
                $("#tishi").stop(true, true).fadeIn('fast');
                $("#tishi").fadeOut(1500);
            }else if($("#tianjiaform input[name='customer_danwei']").val()==''){
                $("#tishi").html('单位名称必须输入');
                $("#tishi").stop(true, true).fadeIn('fast');
                $("#tishi").fadeOut(1500);
            }else{
                var d = {};
                var t = $('#tianjiaform').serializeArray();
                $.each(t, function() {
                  d[this.name] = this.value;
                });
                var data=JSON.stringify(d);
                // alert(data);
                $.ajax({
                    url:"{{url('xiadan/customer')}}",
                    type:'post', //GET
                    async:false,    //或false,是否异步
                    data:{'_token':'{{csrf_token()}}','data':data},
                    dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                    beforeSend:function(){
                        console.log('发送前');
                        $('.z2_loading-bg').show();
                    },
                    success:function(data){
                        if(data=="false"){
                            $('.z2_loading-bg').hide();
                            $("#tishi").html('录入失败');
                            $("#tishi").stop(true, true).fadeIn('fast');
                            $("#tishi").fadeOut(1500);
                        }else if(data=="phone"){
                            $('.z2_loading-bg').hide();
                            $("#tishi").html('客户已存在');
                            $("#tishi").stop(true, true).fadeIn('fast');
                            $("#tishi").fadeOut(1500);
                        }else{
                            window.location.href = "{{url('kehulist')}}";
                        }
                    }, 
                    complete:function(){
                        $('.z2_loading-bg').hide();
                        $('.duihao').show();
                        $('.duihao').hide(1000);
                    }
                })
            }
        });  
    });
    // 执行客户筛选查询
    $(function () {
        $("#sousuo").click(function(){
            var d = {};
            var t = $('#kehusousuo').serializeArray();
            $.each(t, function() {
              d[this.name] = this.value;
            });
            var data=JSON.stringify(d);
            // alert(data);
            $.ajax({
                url:"{{url('kehusousuo')}}",
                type:'post', //GET
                async:false,    //或false,是否异步
                data:{'_token':'{{csrf_token()}}','data':data},
                dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend:function(){
                    console.log('发送前');
                    $('.z2_loading-bg').show();
                },
                success:function(data){
                    if(data=="false"){
                        $('.z2_loading-bg').hide();
                        $("#tishi").html('搜索失败');
                        $("#tishi").stop(true, true).fadeIn('fast');
                        $("#tishi").fadeOut(1500);
                        window.location.href = "{{url('/')}}";
                    }else{
                        var html="";
                        $.each(data.order,function(i,item){
                            html+="<div class=\"cjd_khgllb-bg kehulist\"  myAttr=\"true\"><input type=\"hidden\" name=\"listid\" value=\""+item.id+"\"><p class=\"cjd_khgllb_khname fl\">"+item.customer_name+"<\/p><p class=\"cjd_khgllb_iphone fl\">"+item.customer_phone+"<\/p><span class=\"cjd_khgllb_srtx fr\">生日提醒<\/span><p class=\"cjd_ykxq_sfzh fl\">"+item.customer_danwei+"<\/p><span class=\"cjd_ykxq_sp fr\">"+item.tixing+"<\/span><div class=\"cl\"><\/div><\/div>";
                    　　});
                        $("#kaikuo").html(html);
                        $("#shuliang").val(data.shuliang);
                        // 选择客户之后 发送短信
                        $('.cjd_khgllb-bg').click(function(){
                            if($(this).attr("myAttr")=="true"){
                                $("#customer_ids").val($("#customer_ids").val()+$(this).children().eq(0).val()+',');
                                $(this).attr("myAttr","false");
                                $(this).css('background', '#eaeaea');
                            }else{
                                $("#customer_ids").val($("#customer_ids").val().replace($(this).children().eq(0).val()+',', ""));
                                $(this).attr("myAttr","true");
                                $(this).css('background', '#fff');
                            }
                        })
                    }
                }, 
                complete:function(){
                    location.hash = 'khlb1';
                    $("#khlb1").show();
                    $("#khlb2").hide();
                    $("#khlb3").hide();
                    $("#khlb4").hide();
                    $("#khlb5").hide();
                    $('.z2_loading-bg').hide();
                    $('.duihao').show();
                    $('.duihao').hide(1000);
                }
            })
        });  
    });
    
    $(window).on('hashchange', function (e) {
        var id = location.hash.substr(1);
        $("#" + id).show()

        if (id == "khlb1") {
            $("#khlb1").show();
            $("#khlb2").hide();
            $("#khlb3").hide();
            $("#khlb4").hide();
            $("#khlb5").hide();
            $('.khlb_sx').show();
            $('.cjd_khgllb-bg').css('background', '#fff');
            $('.ym-tit').html('客户列表');
        } else if (id == "khlb2") {
            $("#khlb1").hide();
            $("#khlb2").show();
            $("#khlb3").hide();
            $("#khlb4").hide();
            $("#khlb5").hide();
            $('.khlb_sx').hide();
            $('.ym-tit').html('发送短信');
        } else if (id == "khlb3") {
            $("#khlb1").hide();
            $("#khlb2").hide();
            $("#khlb3").show();
            $("#khlb4").hide();
            $("#khlb5").hide();
            $('.khlb_sx').show();
            $('.ym-tit').html('客户列表筛选');
        } else if (id == "khlb4") {
            $("#khlb1").hide();
            $("#khlb2").hide();
            $("#khlb3").hide();
            $("#khlb4").show();
            $("#khlb5").hide();
            $('.khlb_sx').hide();
            $('.ym-tit').html('编辑客户资料');
        } else if (id == "khlb5") {
            $("#khlb1").hide();
            $("#khlb2").hide();
            $("#khlb3").hide();
            $("#khlb4").hide();
            $("#khlb5").show();
            $('.khlb_sx').hide();
            $('.ym-tit').html('新增客户');
        }
    })
    // 客户列表点击出现筛选
    $('.khtj_sx').click(function () {
        location.hash = 'khlb3';
        $("#khlb1").hide();
        $("#khlb2").hide();
        $("#khlb3").show();
        $("#khlb4").hide();
        $('.khlb_sx').show();
        $('.ym-tit').html('客户列表筛选');
    })
    // 客户列表新增客户添加页面
    $('.khlbxzkh_btn').click(function () {
        location.hash = 'khlb5';
        $("#khlb1").hide();
        $("#khlb2").hide();
        $("#khlb3").hide();
        $("#khlb4").hide();
        $("#khlb5").show();
        $('.khlb_sx').hide();
        $('.ym-tit').html('新增客户');
    })
    // 选择客户列表选项
    $('.cjd_khgllb-bg').click(function(){
        if($(this).attr("myAttr")=="true"){
            $("#customer_ids").val($("#customer_ids").val()+$(this).children().eq(0).val()+',');
            $(this).attr("myAttr","false");
            $(this).css('background', '#eaeaea');
        }else{
            $("#customer_ids").val($("#customer_ids").val().replace($(this).children().eq(0).val()+',', ""));
            $(this).attr("myAttr","true");
            $(this).css('background', '#fff');
        }
    })
    // 点击发送短信按钮
    $('.khlbfsdx_btn').click(function () {
        if($("#customer_ids").val()==""){
            $(".z2_loading-bg").hide();
            $("#tishi").html('没有选择客户');
            $("#tishi").stop(true, true).fadeIn('fast');
            $("#tishi").fadeOut(2000);
        }else{
            // $(".kehulist").attr("myAttr","true");
            $("#listid").val($("#customer_ids").val());
            // $("#customer_ids").val("");
            location.hash = 'khlb2';
            $("#khlb1").hide();
            $("#khlb2").show();
            $("#khlb3").hide();
            $("#khlb4").hide();
            $('.khlb_sx').hide();
            $('.ym-tit').html('发送短信');
        }
    })
    // 点击编辑客户资料按钮
    $('.khlbbjzl_btn').click(function () {
        if($("#customer_ids").val()==""){
            $(".z2_loading-bg").hide();
            $("#tishi").html('没有选择客户');
            $("#tishi").stop(true, true).fadeIn('fast');
            $("#tishi").fadeOut(2000);
        }else{
            $("#listid").val($("#customer_ids").val());
            if($("#listid").val().split(",").length-1 >1){
                $(".z2_loading-bg").hide();
                $("#tishi").html('只能选择一个客户');
                $("#tishi").stop(true, true).fadeIn('fast');
                $("#tishi").fadeOut(2000);
            }else{
               if($("input[name='listid']").val()==''){
                    $("#tishi").html('客户必须选择');
                    $("#tishi").stop(true, true).fadeIn('fast');
                    $("#tishi").fadeOut(1500);
                }else{
                    var d = {};
                    var t = $('#customer_form').serializeArray();
                    $.each(t, function() {
                      d[this.name] = this.value;
                    });
                    var data=JSON.stringify(d);
                    $.ajax({
                        url:"{{url('kehubianji')}}",
                        type:'post', 
                        async:false,    //或false,是否异步
                        data:{'_token':'{{csrf_token()}}','data':data},
                        dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                        beforeSend:function(){
                            console.log('发送前');
                            $(".kehulist").attr("myAttr","true");
                            $("#customer_ids").val("");
                            $('.z2_loading-bg').show();
                        },
                        success:function(data){
                            if(data!=""){
                                $("#customerbianji input[name='id']").val(data.id);
                                $("#customerbianji input[name='customer_laiyuan']").val(data.customer_laiyuan);
                                $("#customerbianji input[name='customer_name']").val(data.customer_name);
                                $("#customerbianji input[name='customer_age']").val(data.customer_age);
                                if(data.customer_sex==1){
                                    $("#nan").attr('checked','checked');
                                }else{
                                    $("#nv").attr('checked','checked');
                                }
                                $("#customerbianji input[name='customer_phone']").val(data.customer_phone);
                                $("#customerbianji input[name='customer_weixin']").val(data.customer_weixin);
                                $("#customerbianji input[name='customer_qq']").val(data.customer_qq);
                                $("#customerbianji input[name='customer_email']").val(data.customer_email);
                                $("#customerbianji input[name='customer_sfz']").val(data.customer_sfz);
                                $("#customerbianji input[name='customer_type']").val(data.customer_type);
                                $("#customerbianji input[name='customer_danwei']").val(data.customer_danwei);
                                $("#customerbianji input[name='customer_beizhu']").val(data.customer_beizhu);
                                $(".kehulist").attr("myAttr","true");
                                $("#customer_ids").val("");
                                location.hash = 'khlb4';
                                $("#khlb1").hide();
                                $("#khlb2").hide();
                                $("#khlb3").hide();
                                $("#khlb4").show();
                                $("#khlb5").hide();
                                $('.khlb_sx').hide();
                                $('.ym-tit').html('编辑客户资料');
                                $('.z2_loading-bg').hide();
                            }
                        }, 
                    })
                } 
            }
            
        }
    })
    // 点击客户编辑资料的保存按钮
    $("#bianjibaoxun").click(function(){
        if($("#customerbianji input[name='customer_laiyuan']").val()==''){
            $("#tishi").html('客户来源必须选择');
            $("#tishi").stop(true, true).fadeIn('fast');
            $("#tishi").fadeOut(1500);
        }else if($("#customerbianji input[name='customer_name']").val()==''){
            $("#tishi").html('客户姓名必须输入');
            $("#tishi").stop(true, true).fadeIn('fast');
            $("#tishi").fadeOut(1500);
        }else if($("#customerbianji input[name='customer_phone']").val() !='' && $("#customerbianji input[name='customer_phone']").val().length !=11){
            $("#tishi").html('客户电话必须为11位');
            $("#tishi").stop(true, true).fadeIn('fast');
            $("#tishi").fadeOut(1500);
        }else if($("#customerbianji input[name='customer_sfz']").val() !='' && $("#customerbianji input[name='customer_sfz']").val().length !=18){
            $("#tishi").html('身份证号码必须18位');
            $("#tishi").stop(true, true).fadeIn('fast');
            $("#tishi").fadeOut(1500);
        }else if($("#customerbianji input[name='customer_type']").val()==''){
            $("#tishi").html('客户类别');
            $("#tishi").stop(true, true).fadeIn('fast');
            $("#tishi").fadeOut(1500);
        }else if($("#customerbianji input[name='customer_danwei']").val()==''){
            $("#tishi").html('单位名称必须输入');
            $("#tishi").stop(true, true).fadeIn('fast');
            $("#tishi").fadeOut(1500);
        }else{
            var d = {};
            var t = $('#customerbianji').serializeArray();
            $.each(t, function() {
              d[this.name] = this.value;
            });
            var data=JSON.stringify(d);
            $.ajax({
                url:"{{url('customerbianji')}}",
                type:'post', //GET
                async:false,    //或false,是否异步
                data:{'_token':'{{csrf_token()}}','data':data},
                dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend:function(){
                    console.log('发送前');
                    $('.z2_loading-bg').show();
                },
                success:function(data){
                    if(data=="false"){
                        $('.z2_loading-bg').hide();
                        $("#tishi").html('录入失败');
                        $("#tishi").stop(true, true).fadeIn('fast');
                        $("#tishi").fadeOut(1500);
                    }else if(data=="phone"){
                        $('.z2_loading-bg').hide();
                        $("#tishi").html('客户已存在');
                        $("#tishi").stop(true, true).fadeIn('fast');
                        $("#tishi").fadeOut(1500);
                    }else{
                        $('.z2_loading-bg').hide();
                        $('.duihao').show();
                        $('.duihao').hide(1000);
                        // window.location.reload();
                    }
                }, 
            })
        }
    })
    // 点击短信列表选项
    $('.khlb_dxlb').click(function () {
        $(".duanxinlist").css('background', '#fff');
        $("#moban").val($(this).children().eq(0).val());
        $(this).css('background', '#eaeaea');
    });
    // 执行短信发送
    $("#fasong").click(function(){
        if($("input[name='listid']").val()==''){
            $("#tishi").html('客户必须选择');
            $("#tishi").stop(true, true).fadeIn('fast');
            $("#tishi").fadeOut(1500);
        }else if($("input[name='moban']").val()==''){
            $("#tishi").html('短信模板必须选择');
            $("#tishi").stop(true, true).fadeIn('fast');
            $("#tishi").fadeOut(1500);
        }else{
            var d = {};
            var t = $('#customer_form').serializeArray();
            $.each(t, function() {
              d[this.name] = this.value;
            });
            var data=JSON.stringify(d);
            $.ajax({
                url:"{{url('customerduanxin')}}",
                type:'post', 
                async:false,    //或false,是否异步
                data:{'_token':'{{csrf_token()}}','data':data},
                dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend:function(){
                    console.log('发送前');
                    $('.z2_loading-bg').show();
                },
                success:function(data){
                    if(data=="yuebuzu"){
                        $("#tishi").html('余额不足！');
                        $("#tishi").stop(true, true).fadeIn('fast');
                        $("#tishi").fadeOut(2000);
                    }else{
                        $(".kehulist").attr("myAttr","true");
                        $("#customer_ids").val("");
                        $(".z2_loading-bg").hide();
                        $("#tishi").html('成功'+data.chenggong+'条，失败'+data.shibai+'条。');
                        $("#tishi").stop(true, true).fadeIn('fast');
                        $("#tishi").fadeOut(2000);
                        window.location.reload();
                    }
                }, 
            })
        }
    });
    // 点击编辑客户资料保存按钮后 取消点击客户列表的背景色
    // $('.khlb_bjzl-btn').click(function(){
    //     $('.cjd_khgllb-bg').css('background', '#fff');
    // })
    
    </script>
</html>

<!-- 问题：列表冲突，如果可以多选发送短信，就没有办法单选编辑客户信息 -->